// app.js
import {
  getEnvironment,
  getUserInfo
} from './utils/util.js'
import HttpClint from './utils/request.js'

App({
  $axios: HttpClint,
  // $getDict: getDict,
  async onLaunch() {
    wx.removeStorage({
      key: "token"
    })
    wx.removeStorage({
      key: "environment"
    })
    console.log(__wxConfig.envVersion)
    // wx.setStorageSync('token', 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjY5NDBlZjI5LTk3ZGMtNDZlNi05OTc0LTUwODI3ZGFkM2IxYSJ9.oFLwuD5uhOR0Fj4SIAAIw0bD__hbrfO84fePUZmccI80OfLhKhi7wFjSOrcOr-iV1xN__fDASNu176N_uPYM1A')
    getEnvironment()
    this.getUser()
  },
  onShow(data) {},
  globalData: {
    userInfo: null
  },
  async getUser() {
    let token = wx.getStorageSync('token')
    let that = this
    if (!token && !wx.getStorageSync('environment')) {
      return setTimeout(() => {
        that.getUser()
      }, 1000);
    }
    let user = wx.getStorageSync('userInfo')
    if (!user) {
      this.globalData.userInfo = await getUserInfo()
    }
  }
})